; WINLIB/IO/STDIO.ASM 
; This file contains the Standard Input Output Functions
; for a simple Window.
; Function : win_new_line
; What it does?
; Gets the cursor position,
; DH = Y Axis
; DL = X Axis
; DL is set to 5 the start point of the Window.
; DH is incremented and the cursor is moved By Parameters
; DH = 5
; DL = [PREDL] + 1 (Where PREDL was the DL returned by the OS_GET_CURSOR_POS
win_new_line:
	call os_get_cursor_pos
	mov dl,5
	inc dh
	call os_move_cursor
	ret

; Function win_print_string
; Prints string in a Window.
; If the Y Position of the String is > 5
; then it prints a newline
win_print_string:
	mov ah,0x0e
	lodsb
	cmp al,0
	je .done
	call os_get_cursor_pos ; Get the cursor position
	cmp dh,22
	je .redraw 
	cmp dl,69
	je .next_line
	jmp .print
.next_line:
	mov dl,5
	inc dh
	call os_move_cursor
	jmp .print
.print:
	int 0x10
	jmp win_print_string
.redraw:
	call win_set_up
	jmp win_print_string
.done:
	ret
; Function : win_set_up
; Sets up the Window.
win_set_up:
	push di ; Preserve DI
	mov ax,1003h
	mov bx,0
	int 0x10
	call os_clear_screen
	mov bl, 0x1F	
	mov dl, 5		
	mov dh, 2		
	mov si, 68		
	mov di, 3		
	call os_draw_block
	mov dh,2
	mov dl,5
	call os_move_cursor
	pop di
	mov si,di
	call os_print_string
	mov dh,2
	mov dl,66
	call os_move_cursor
	mov si,close
	call os_print_string
	mov dh,2
	mov dl,69
	call os_move_cursor
	mov si,max
	call os_print_string
	mov bl, 0x9F	; White on red
	mov dl, 5		; Start X position
	mov dh, 3		; Start Y position
	mov si, 68		; Width
	mov di, 22		; Finish Y position
	call os_draw_block
	mov dh,3
	mov dl,5
	call os_move_cursor
	ret
	max db '[',0xFE,']',0
	